package ch.elca.lol.puissance4.util;

import ch.elca.lol.puissance4.game.Token;

/**
 * Counts successive tokens on a board. Keeps track of the last kind of token that was counted, and
 * the number of successive tokens of this kind. Practical when checking whether there's a connect4 on a board.
 */
public class TokenCounter {
	private Token last = null;
	private int count = 0;
	
	public void reset() {
		last = null;
		count = 0;
	}
	
	public void count(Token t) {
		if(t == last)
			count++;
		else {
			count = 1;
			last = t;
		}
	}
	
	public int getCount() {
		return count;
	}
	
	public Token getToken() {
		return last;
	}
	
	public boolean increaseAndCheckFour(Token incr, Token player) {
		count(incr);
		return last == player && count >= 4;
	}
}
